/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean;

import entity.AccessRightsEntity;
import entity.StaffAccountEntity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.PhaseEvent;
import javax.faces.model.SelectItem;
import session.stateless.TCubeSessionBean;
import util.entityhelper.StaffAccountState;
import util.enumeration.AccessRight;

@ManagedBean
@RequestScoped
public class StaffEditAccessRightsManagedBean {

    private List<StaffAccountState> staffAccountState = new ArrayList();
    @EJB
    private TCubeSessionBean sessionBean;
    private SelectItem[] accessRightSelectItems;
    private AccessRightsEntity[] selectedAccessRights;
    private List<AccessRight> accessRightsList;
    private static int num;

    public StaffEditAccessRightsManagedBean() {
    }

    public void initView(PhaseEvent event) {
        AccessRight[] access = AccessRight.values();
        accessRightSelectItems = new SelectItem[access.length];
        for (int i = 0; i < accessRightSelectItems.length; i++) {
            accessRightSelectItems[i] = new SelectItem(access[i]);
        }
    }

    public List<StaffAccountState> getStaffAccountState() {
        if (num == 0) {
            List<StaffAccountEntity> tempList = new ArrayList();
            tempList = sessionBean.getTCubeAccountList();
            System.out.println("Size: " + tempList.size());
            for (int i = 0; i < tempList.size(); i++) {
                StaffAccountEntity c = (StaffAccountEntity) tempList.get(i);
                System.out.println("Account ID: " + tempList.get(i).getId());
                System.out.println("Username: " + tempList.get(i).getUsername());
                System.out.println("Creation Date: " + tempList.get(i).getCreationDate());
                System.out.println("AccessRights: " + c.getAccessRights().size());
                StaffAccountState s = new StaffAccountState(tempList.get(i).getId(), tempList.get(i).getUsername(), tempList.get(i).getPassword(), tempList.get(i).getCreationDate(), tempList.get(i).getPasswordChangeDate(), tempList.get(i).getStatus(), c.getAccessRights(), tempList.get(i).getStaff());
                s.setAccessRights(c.getAccessRights());
                System.out.println("StateCreated");
                staffAccountState.add(s);
            }
            System.out.println("State Added");
            System.out.println(staffAccountState.size());
        }
        num++;
        return staffAccountState;
    }

    public void setStaffAccountState(List<StaffAccountState> staffAccountState) {

        this.staffAccountState = staffAccountState;
    }

    public AccessRightsEntity[] getSelectedAccessRights() {
        return selectedAccessRights;
    }

    public void setSelectedAccessRights(AccessRightsEntity[] selectedAccessRights) {
        this.selectedAccessRights = selectedAccessRights;
    }

    public SelectItem[] getAccessRightSelectItems() {
        return accessRightSelectItems;
    }
    
    public void setAccessRightSelectItems(SelectItem[] accessRightSelectItems) {
        this.accessRightSelectItems = accessRightSelectItems;
    }

    public List<AccessRight> getAccessRightsList() {
        return accessRightsList;
    }

    public void setAccessRightsList(List<AccessRight> accessRightsList) {
        this.accessRightsList = accessRightsList;
    }
}
